package com.zx.role.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zx.role.domain.SysUser;
import com.zx.role.execption.MyExecption;
import com.zx.role.mapper.SysUserMapper;
import com.zx.role.service.ISysUserService;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Map;
import java.util.function.Function;

public class ISysUserSericeImpl extends ServiceImpl<SysUserMapper,SysUser> implements ISysUserService {


//    /**
//     * 添加没有回滚
//     * @param sysUser
//     */
//    @Override
//    public void insertObject(SysUser sysUser) {
//        int insert = baseMapper.insert(sysUser);
//        //遇到了除零异常，事务没有回滚，正常插入了数据
//        int i = 1/0;
//    }

//    /**
//     * 添加正常回滚
//     * @param sysUser
//     */
//    @Override
//    @Transactional
//    public void insertObject(SysUser sysUser){
//        int insert = baseMapper.insert(sysUser);
//        //遇到了除零异常，事务正常回滚
//        //原因：@Transactional
//        int i = 1/0;
//    }

//    /**
//     * 添加正常回滚
//     * @param sysUser
//     */
//    @Override
//    @Transactional(rollbackFor = NullPointerException.class)
//    public void insertObject(SysUser sysUser){
//        int insert = baseMapper.insert(sysUser);
//        //遇到了除零异常，虽然指定了空指针异常，但是正常回滚
//        //原因：因为运行时异常，指不指定都会正常回滚
//        int i=1/0;
//    }

//    /**
//     * 添加回滚失败
//     * @param sysUser
//     * @throws MyExecption
//     */
//    @Override
//    @Transactional(rollbackFor = NullPointerException.class)
//    public void insertObject(SysUser sysUser) throws MyExecption {
//        int insert = baseMapper.insert(sysUser);
//        //事务正常提交了，rollbackFor指定的异常生效了,但是回滚失败
//        //原因：自定义异常不属于运行时异常，所以回滚失败
//        throw new MyExecption("自定义的异常");
//    }


    /**
     * 添加回滚成功
     * @param sysUser
     * @throws MyExecption
     */
    @Override
    @Transactional(rollbackFor = MyExecption.class)
    public void insertObject(SysUser sysUser) throws MyExecption {
        int insert = baseMapper.insert(sysUser);
        //事务正常提交了，rollbackFor指定的异常生效了，回滚成功
        //原因：rollbackFor指定的自定义的异常生效
        throw new  MyExecption("定义的异常");
    }
//
//    @Override
//    public void insertObject(SysUser sysUser){
//        int insert = baseMapper.insert(sysUser);
//        int i = 1/0;
//    }

























    @Override
    public boolean saveBatch(Collection<SysUser> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<SysUser> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<SysUser> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(SysUser entity) {
        return false;
    }

    @Override
    public SysUser getOne(Wrapper<SysUser> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Map<String, Object> getMap(Wrapper<SysUser> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<SysUser> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }


    @Override
    public Class<SysUser> getEntityClass() {
        return null;
    }
}
